package com.admin.action.bookaction;

import com.admin.Action;
import com.admin.dto.BookListBean;
import com.admin.service.bookservice.BookServiceImpl;
import com.admin.service.bookservice.BookServiceInF;
import com.borrower.service.BorrowerServiceImpl;
import com.google.gson.Gson;
import com.pojo.BorrowerBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class FindByBookName extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }


        String bookName=request.getParameter("bookName");
        String idCard=request.getParameter("card");
        BookServiceInF bookService = new BookServiceImpl();



        BorrowerServiceImpl borService = new BorrowerServiceImpl();

        BorrowerBean borrowerBean = new BorrowerBean();
        borrowerBean.setIdCard(idCard);
        //判断是否输入借阅者id
       List<BorrowerBean> listBor=borService.getBorInfoByIdCard(borrowerBean);

//       if(listBor==null){
//           System.out.println("listBor is null");
//           out.print(false);
//       }else {
           BookListBean bookListBean=new BookListBean();
           bookListBean.setBookName(bookName);

           //模糊查询书籍
           List<BookListBean> list= bookService.queryBookInfoByBookName(bookName);

           System.out.println(list);
           Gson gson = new Gson();
           String jsonStr =   gson.toJson(list);
           System.out.println(jsonStr);
           out.print(jsonStr);
//       }





    }
}
